<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>
    <head>
        <title>添加新记录</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
        <link rel="stylesheet" href="/Public/User/css/weui.css"/>
        <link rel="stylesheet" href="/Public/User/css/example.css"/>
        <link rel="stylesheet" href="/Public/User/css/swiper.min.css">
        <script src="/Public/User/newjs/jquery.js"></script>
        <script src="/Public/User/js/swiper.min.js"></script>
        <script src="/Public/User/js/dom_tool.js"></script>
        <script src="/Public/User/js/layer.js"></script>
        <script src="<?php echo $dic;?>"></script>
        <script src="<?php echo $layer;?>"></script>
        <!--树形结构-->
        <link rel="stylesheet" href="/Public/User/css/zTreeStyle.css">
        <link rel="stylesheet" href="/Public/User/css/treeDemo.css" type="text/css">
        <script src="/Public/User/newjs/jquery.ztree.core.js"></script>
        <script src="/Public/User/newjs/myztree.js"></script>
        <!-- 二次定义weui样式开始 -->
        <style>
            . .weui-cell__hd{
                width:40%;
                padding:0px;
            }
            .weui-cell{
                width:60%;
            }
            .weui-cell_vcode{
                width:100%;
            }
            .weui-label{
                width:140px;
                overflow: hidden;
            }
            .operation_div,.operation_div_2{
                padding:18px;
            }
            .weui-input{
                padding-left:0px;
            }
            .ztree * {
                font-size: 18px;
            }
            .file_input {
                width:90%;
                border: 0;
                outline: 0;
                -webkit-appearance: none;
                background-color: transparent;
                font-size: inherit;
                color: inherit;
                height: 1.41176471em;
                line-height: 1.41176471;
            }
            .filelable{
                margin-left:15px;
                line-height: 1.41176471;
                font-size: 18px;
            }
            .file_info{
                margin-left:80px;
            }
            span{
                margin-right:10px;
            }
            .operation_div_2 input{
                width:23%;
                margin-right: 2%;
                display: inline;
            }
        </style>
        <!-- 二次定义weui样式结束 -->
        <script src="/Public/User/js/dom_tool.js"></script>
        <script>
            var sj_info = eval(<?php echo ($sj_info); ?>); //时间验证配置
            $(function(){
                var json = eval(<?php echo ($sublist); ?>);
                var kz_json = eval(<?php echo ($kz_info); ?>);  //扩展配置数据
                var menu = '<?php echo ($menu); ?>';
                var uuid = '<?php echo ($uuid); ?>';  //员工编码
                var data = {
                    name:menu,
                    action:'/User/Info/addok',
                    method:'post',
                    json:json,
                    dic:dic,
                    layer_js: layer_js,
                    kz_json:kz_json
                };
                addNew(data);
                //检测表单提交数据合法性
                $('.btn-default').click(function(){
                    //检测附件的大小和类型
                    var tob = 0;
                    $('.file_input').each(function(){
                        var fjresolt = fileFJSize($(this)[0]);
                        if(!fjresolt){
                            tob++;
                        }
                    });
                    if(tob){
                        return false;
                    }
                    //验证时间规则
                    for(var i in sj_info){
                        var bj_val = $('input[name='+i+']').val();
                        var bj_name = $('input[name='+i+']').parent().parent().parent().find('label').text();
                        if(bj_name.indexOf('*')>-1){
                            bj_name = bj_name.substr(0, bj_name.length - 1);
                        }
                        var b_bj_val = $('input[name='+sj_info[i].max+']').val();
                        var b_bj_name = $('input[name='+sj_info[i].max+']').parent().parent().parent().find('label').text();
                        if(b_bj_name.indexOf('*')>-1){
                            b_bj_name = b_bj_name.substr(0, b_bj_name.length - 1);
                        }

                        if(sj_info[i].method == 1){
                            if(bj_val && b_bj_val && bj_val <= b_bj_val){
                                layer.alert(bj_name+' 不能小于或等于 '+b_bj_name);
                                return false;
                            }
                        }else if(sj_info[i].method == 2){
                            if(bj_val && b_bj_val && bj_val < b_bj_val){
                                layer.alert(bj_name+' 不能小于 '+b_bj_name);
                                return false;
                            }
                        }
                    }
                });

                //唯一性验证
                $('.checkWyx').change(function () {
                    var self = $(this);
                    var val = $(this).val();
                    var zd_name = $(this).attr('name');
                    var form = $(this).parents('form');
                    if (val == '是') {
                        var caption = $(this).parent().parent().parent().find('label').text();
                        caption = caption.substr(0, caption.length - 1);
                        var data = {uuid: uuid, item: menu, name: zd_name};
                        var resolot = aa(data);
                        if (resolot.type == 2) {
                            var text = '字段 ' + caption + ' 已经存在唯一值,您是保留当前值,更改其他该字段的值,还是更改当前字段的值该为否,其他记录值不变?';
                            layer.confirm(text, {
                                btn: ['保留', '不保留'] //按钮
                            }, function () {
                                var zj_input = '<input type="hidden" name="upd-' + zd_name + '" value="'+resolot.key+'">';
                                form.append(zj_input);
                                layer.msg(caption + '的值为是,将更改其他记录值!');
                            }, function () {
                                self.val('否');
                                layer.msg(caption + '的值改为否,其他记录此字段值不变!');
                            });
                        }
                    }

                });
                function aa(data) {
                    var resolt = null;
                    $.ajax({
                        url: '/User/Info/checkWyx',
                        type: 'post',
                        data: data,
                        async: false,
                        success: function (e) {
                            resolt = e;
                        }
                    });
                    return resolt;
                }

                //点击取消按钮隐藏alert提示
                $('#dialog2_but').bind('click',function(){
                    $('#dialog2').hide();
                });
                //监听返回首页按钮 返回上一页
                $('.callback_button').bind('click',function(){
                    history.go(-1);
                });
                //初始化树形结
                for(var i in layer_id){
                    $("#"+i).on("click",{i: i},function (e) {
                        var q=0;
                        $.fn.zTree.init($("#tree"), setting,layer_js[layer_id[e.data.i]]);
                        showMenu($(this));
                    });
                }
                //重新调整树形结构宽度
                $(window).resize(function () {
                    $("#menuContent").hide();
                    $("#menuContent ul").width($("#inputText_0").parent('div').width()+"px");
                });
                $("#menuContent ul").width($("#inputText_0").parent('div').width()+"px");
            });
            // 附件上传
            function add_file(e){
                var pNode=$(e).parents('.file_warp');
                pNode.parent('div').append(pNode.clone().children('input').val('').end()).children('.file_warp').eq(0).siblings().find('.file_add').attr("class",'file_remove').find('a').attr("onclick",'remove_file(this)').html("[-]");
            }
            function remove_file(e) {
                $(e).parents('.file_warp').remove();
            }
            function  remove_result(e) {
                $(e).parents('.file_info').remove();
            }
            //检测附件
            function fileFJSize(obj,tob){
                if(!obj.value){
                    return true;
                }
                var photoExt = obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();//获得文件后缀名
                var filetype = '.jpg,.gif,.png,.jpeg,.xls,.xlsx,.doc,.docx,.ppt,.pptx';
                //alert(filetype.indexOf(photoExt));return false;
                if(filetype.indexOf(photoExt)<0){
                    tob++;
                    layer.alert("上传的只支持'jpg', 'gif', 'png', 'jpeg','xls','xlsx','doc','docx','ppt','pptx'的格式!");
                    return false;
                }
                var fileSize = 0;
                var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
                if (isIE && !obj.files) {
                    var filePath = obj.value;
                    var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
                    var file = fileSystem.GetFile (filePath);
                    fileSize = file.Size;
                }else {
                    fileSize = obj.files[0].size;
                }
                fileSize=Math.round(fileSize/1024*100)/100; //单位为KB
                if(fileSize >= 2000){
                    tob++;
                    layer.alert("上传的附件大小超过2M，请重新上传!");
                    return false;
                }
                return true;
            }
        </script>
    </head>
    <body>
        <div>
            <div class="content_wrap">
            </div>
            <div id="menuContent" class="menuContent" style=" display:none;position: absolute;">
                <ul id="tree" class="ztree" style="margin-top:0; width:370px; height: 300px;"></ul>
            </div>
        </div>
		<div id="dialog2" style="display:none;">
		    <div class="weui-mask"></div>
			<div class="weui-dialog">
				<div class="weui-dialog__hd"><strong class="weui-dialog__title">操作提示</strong></div>
				<div class="weui-dialog__bd" id="dialog2_msg">
				</div>
				<div class="weui-dialog__ft">
				<a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary" id="dialog2_but">好的</a>
				</div>
			</div>
		</div>
    </body>
</html>